package Various;

import Interface.JSelect;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.text.JTextComponent;

public class VerifSaisie {

    public static ImageIcon imgPasOk = new ImageIcon("./images/pasok.gif");
    public static ImageIcon imgOk = new ImageIcon("./images/ok.gif");

    //***********************  Verification de saisie g�n�rale  ***********************

    public static boolean hasMinLenght(int lenght, JTextComponent jtComponent) {
        if (jtComponent.getText().length() >= lenght) {
            return true;
        }
        return false;
    }

    public static boolean hasMinLenght(int lenght, JTextComponent jtComponent, JLabel jblVerif) {
        if (hasMinLenght(lenght, jtComponent)) {
            jblVerif.setIcon(imgOk);
        }
        else {
            jblVerif.setIcon(imgPasOk);
        }
        return hasMinLenght(lenght, jtComponent);
    }

    public static boolean isSelectOk(JSelect jSelect) {
        if (!jSelect.getSelectedItem().equals(jSelect.getDefaultSelection())) {
            return true;
        }
        return false;
    }

    public static boolean isSelectOk(JSelect jSelect, JLabel jblVerif) {
        if (isSelectOk(jSelect)) {
            jblVerif.setIcon(imgOk);
        }
        else {
            jblVerif.setIcon(imgPasOk);
        }
        return isSelectOk(jSelect);
    }

    public static boolean isInteger(String stringToTest, JLabel jblVerif) {
        try {
            Integer.parseInt(stringToTest);
        }
        catch (NumberFormatException ex) {
            jblVerif.setIcon(imgPasOk);
            return false;
        }
        jblVerif.setIcon(imgOk);
        return true;
    }

    public static boolean isAllOk(boolean... values) {
        boolean allOk = true;
        for (boolean value : values) {
            allOk = allOk && value;
        }
        return allOk;
    }

  
}
